/*
 * Copyright Eduardo Aponte 2013
 * aponteeduardo@gmail.com
 */
#include <eyelink.h>
#include "mex.h"



void _main( char FARTYPE *ops )
{
    eyelink_set_name( ops );
}


void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    int i;
    /* Buffer size */
    int bs; 
    /* Matlab buffer: WARNING no protection against buffer over load */
    char *mb;
    /* Eyelink char. To support compatibility.*/
    char FARTYPE *elb;
    
    
    /* Verify input arguments. */
    if(nrhs != 1 ) {
        mexErrMsgTxt("Incorrect number of inputs.");
    } else if( nlhs != 0 ) {
        mexErrMsgTxt("Too many output arguments.");
    }
    
    if ( mxIsChar(*prhs) != 1)
      mexErrMsgTxt( "name must be a string.");
      
    mb  = mxArrayToString(*prhs);
    
    if(mb == NULL) 
      mexErrMsgTxt("Could not convert input to string.");
    
    bs  = (mxGetM(*prhs) * mxGetN(*prhs));
    elb = mxCalloc(bs,sizeof(char FARTYPE));    
    
    for (i = 0; i < bs-1; i++)
        elb[i] = (char FARTYPE ) mb[i];
    
    _main( elb );    
    mxFree( elb );
    return;
}


